﻿#！

import os
import xml.etree.ElementTree as XML

#删除tag字符串中的namespace
def remove_ns(tag):
	pos=tag.find('}')
	return tag[pos+1:]

#获取Condition属性字符串中的configuration子串 Relase or Debug
def get_configuration(s):
	sep0="'=='"
	sep1='|'
	start=s.find(sep0)+len(sep0)
	end=s.find(sep1,start)
	return s[start:end]

#获取Condition属性字符串中的configuration子串 Win32 or x64
def get_platform(s):
	sep='|'
	pos=s.rfind(sep)+len(sep)
	return s[pos:-1]

#	获取某个子节点
def find_subelement(tag,parent):
	for item in parent:
		t=remove_ns(item.tag)
		if(t==tag):
			return item
	
#
def modify_PropertyGroup(node):
	attrib=node.attrib
	condition=attrib['Condition']
	conf=get_configuration(condition)
	plat=get_platform(condition)
	print("%s+%s" %(conf,plat))

#
def	get_propertyGroup(item, prjProp):
	con0=item.attrib['Condition']
	for prop in prjProp:
		con1=prop.attrib['Condition']
		if(con0==con1):
			return prop
			
#

		

#
def modify_msproj(path):
	print(path)
	tree=XML.parse(path)
	root=tree.getroot()
	prjProp0=[]
	prjProp1=[]
	for item in root:
		tag=remove_ns(item.tag)
		if(tag=="PropertyGroup"):
			attrib=item.attrib
			if 'Condition' in attrib:
				if 'Label' not in attrib:
					prjProp0.append(item)
				else:
					prjProp1.append(item)
	for prop0 in prjProp0:
		prop1=get_propertyGroup(prop0,prjProp1)
		configuration_type=find_subelement('ConfigurationType',prop1)
		configuration_type_text=configuration_type.text
		if(configuration_type_text=='StaticLibrary'):
			#
		elif configuration_type_text=='Application':
			#
		elif configuration_type_text=='DynamicLibrary':
			#
				#modify_PropertyGroup(item)


prj_path="D:\\MyPrograms\\BroadcastServer\\NetMotion\\"

files=os.listdir(path=prj_path)
for f in files:
	f=os.path.join(prj_path,f)
	if(os.path.isfile(f)):
		f=f.lower()
		ext=os.path.splitext(f)
		if(ext[1]==".vcxproj"):
			modify_msproj(f)
	
